#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N = 2e4 + 10, M = 2e5 + 10;
int dis[N];
bool st[N];
int h[N], e[M], ne[M], w[M], idx;
int n, m;
void add(int a, int b, int c)
{
	e[idx] = b;
	ne[idx] = h[a];
	w[idx] = c;
	h[a] = idx++;
}
void spfa()
{
	memset(dis, 0x3f, sizeof(dis));
	memset(st, 0, sizeof(st));
	dis[1] = 0;
	queue<int>q;
	q.push(1);
	st[1] = 1;
	while (q.size()) {
		int t = q.front();
		q.pop();
		st[t] = 0;
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis[j] > dis[t] + w[i]) {
				dis[j] = dis[t] + w[i];
				if (!st[j]) {
					st[j] = 1;
					q.push(j);
				}
			}
		}
	}
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b, c;
		scanf_s("%d%d%d", &a, &b, &c);
		add(a, b, c);
		//add(b, a, c);
	}
	spfa();
	for (int i = 2; i <= n; i++) {
		cout << dis[i] << endl;
	}
	return 0;
}